﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Truextend.Common.Data
{
    /// <summary>
    /// Repository Interface defines the base
    /// functionality required by all Repositories.
    /// </summary>
    /// <typeparam name="TEntity">
    /// The entity type that requires a Repository.
    /// </typeparam>
    /// <typeparam name="TContext"> </typeparam>
    public interface IRepository<TEntity>
    {
        //DbTransaction BeginTransaction();
        void Add(TEntity entity);
        void AddOrAttach(TEntity entity);
        void DeleteRelatedEntries(TEntity entity);
        //void DeleteRelatedEntries(E entity, ObservableCollection<string> keyListOfIgnoreEntites);
        void Delete(TEntity entity);
        int Save();

        IQueryable<TEntity> DoQuery(string entitySetName);
        IQueryable<TEntity> DoQuery();
        IQueryable<TEntity> DoQuery(string entitySetName, ISpecification<TEntity> where);
        IQueryable<TEntity> DoQuery(ISpecification<TEntity> where);
        IQueryable<TEntity> DoQuery(int maximumRows, int startRowIndex);
        IQueryable<TEntity> DoQuery(Expression<Func<TEntity, object>> sortExpression);
        IQueryable<TEntity> DoQuery(Expression<Func<TEntity, object>> sortExpression,
                    int maximumRows, int startRowIndex);

        IList<TEntity> SelectAll(string entitySetName);
        IList<TEntity> SelectAll();
        IList<TEntity> SelectAll(string entitySetName, ISpecification<TEntity> where);
        IList<TEntity> SelectAll(ISpecification<TEntity> where);
        IList<TEntity> SelectAll(int maximumRows, int startRowIndex);
        IList<TEntity> SelectAll(Expression<Func<TEntity, object>> sortExpression);
        IList<TEntity> SelectAll(Expression<Func<TEntity, object>> sortExpression,
                    int maximumRows, int startRowIndex);

        TEntity SelectByKey(string key);

        bool TrySameValueExist(string fieldName, object fieldValue, string key);
        bool TryEntity(ISpecification<TEntity> selectSpec);

        int GetCount();
        int GetCount(ISpecification<TEntity> selectSpec);
    }
}
